package com.git.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.git.domain.AjaxJson;
import com.git.domain.Book;
import com.git.service.DemoService;

@Controller
public class DemoController {
	@Autowired
	private DemoService demoService;
	
	@RequestMapping("get")
	public ResponseEntity<AjaxJson> get(){
		return ResponseEntity.status(200).body(new AjaxJson(true,"success",null));
	}
	@RequestMapping("init")
	public ResponseEntity<AjaxJson> init(){
		this.demoService.init();
		return ResponseEntity.status(200).body(new AjaxJson(true,"success",null));
	}
	
	
	@RequestMapping("searchType")
	public ResponseEntity<AjaxJson> searchType(String key) throws Exception{
		key = new String(key.getBytes("iso-8859-1"), "utf-8");
		List<Book> books = this.demoService.searchType(key);
		
		return ResponseEntity.status(200).body(new AjaxJson(true,"success",books));
	}
	@RequestMapping("searchContext")
	public ResponseEntity<AjaxJson> searchContext(String key) throws Exception{
		key = new String(key.getBytes("iso-8859-1"), "utf-8");
		List<Book> books = this.demoService.searchContext(key);
		
		return ResponseEntity.status(200).body(new AjaxJson(true,"success",books));
	}
	
	
	
}
